from typing import List

def build_regex_trie(words: List[str]) -> str:
    if not words:
        return ""

    # 构建前缀树
    trie = {}
    for word in words:
        node = trie
        for char in word:
            node = node.setdefault(char, {})

    # 递归生成正则
    def build(node, prefix):
        if not node:
            return prefix

        # 如果只有一个子节点，继续合并
        if len(node) == 1:
            char, next_node = next(iter(node.items()))
            return build(next_node, prefix + char)

        # 多个子节点，分组处理
        parts = []
        for char, next_node in sorted(node.items()):
            parts.append(build(next_node, char))
        return prefix + "(" + "|".join(parts) + ")"

    return build(trie, "")

# 示例
words = ['a', 'ab', 'bc', 'f', 'e']
regex = build_regex_trie(words)
print(regex)